// extractpdf.h
#ifndef EXTRACTPDF_H
#define EXTRACTPDF_H

#include <string>
#include <functional>
#include <map>
#include <vector>
#include <memory>
class PDFDoc;
class CImageOutputDev;
#include <cpp/poppler-document.h>
#include <cpp/poppler-page.h>
enum class ContentType { content_text, content_img };

typedef std::function<bool(int pageNumber, ContentType type, const std::vector<char>&, const char *ext)> PageDataCallback;



class PdfExtractor {
public:
    enum class ImageFormat { PNG, JPEG, BMP };
    enum class ExtractionMode { TextOnly, ImagesOnly, TextAndImages };
    
    PdfExtractor();
    ~PdfExtractor();
    
    bool extractPdfTextAndImagesFromPage(int pageIdx, PageDataCallback callback, ImageFormat imageFormat, ExtractionMode mode);
    bool setupFilePath(const std::string &pdfPath);
    int getPageCount() const;
    // handleSave =true 外部保存，否则自动保存
    static bool extractAllPdfTextAndImages(const std::string& pdfPath,PageDataCallback callback, ImageFormat imageFormat, ExtractionMode mode);

private:
    std::unique_ptr<PDFDoc> m_doc;
    std::unique_ptr<poppler::document> m_popplerDoc;
    CImageOutputDev* m_imgOut;
    int m_numPages;
};

#endif // EXTRACTPDF_H